/**
 * 
 */
package org.cuatrovientos.struts;


import com.opensymphony.xwork2.ActionSupport;

/**
 * Hello simple sample Struts2 action
 * @author Pablo Guerrero
 *
 */
public class NewCar extends ActionSupport {
	
	private String message;
	private String brand;
	private String plate;
	
	/* (non-Javadoc)
	 * @see com.opensymphony.xwork2.ActionSupport#execute()
	 */
	@Override
	public String execute() throws Exception {
		//INSERTS INTO DATABASE
		/**if (brand.equals("") || plate.equals("")){
			if(brand.equals("")){
				message = "You have to write something in the brand";
				return ERROR;
			}
			if(plate.equals("")){
				message = "You have to write something in the plate";
				return ERROR;
			}else{
				message ="The brand and the plate are empty, you have to write something";
				return ERROR;
			}
			
		}			
			Car newCar = new Car(brand,plate);
			CarDAO carDAO = new CarDAO();
			carDAO.insert(newCar);
			message = "New Car added";*/
			return SUCCESS;				
	}

	/**
	 * this insert the new employee
	 * @return SUCCESS
	 */
	public String insertCar(){		
		if (brand.equals("") || plate.equals("")){
			if(brand.equals("")){
				message = "You have to write something in the brand";
				return ERROR;
			}
			if(plate.equals("")){
				message = "You have to write something in the plate";
				return ERROR;
			}else{
				message ="The brand and the plate are empty, you have to write something";
				return ERROR;
			}
			
		}
		CarDAO carDAO = new CarDAO();
		Car newCar = new Car(brand, plate);
		carDAO.insert(newCar);
		
		return SUCCESS;
		
	}
	
	/* (non-Javadoc)
	 * @see com.opensymphony.xwork2.ActionSupport#input()
	 */
	@Override
	public String input() throws Exception {
		
		return super.input();		
	}

	/**
	 * @return the name
	 */
	public String getBrand() {
		return brand;
	}

	/**
	 * @param brand the brand's name to set
	 */
	public void setBrand(String brand) {
		this.brand = brand;
	}

	/**
	 * @return the plate
	 */
	public String getPlate() {
		return plate;
	}

	/**
	 * @param plate the plate to set
	 */
	public void setPlate(String plate) {
		this.plate = plate;
	}

	/**
	 * @return the message
	 */
	public String getMessage() {
		return message;
	}

	/**
	 * @param message the message to set
	 */
	public void setMessage(String message) {
		this.message = message;
	}
}
